package com.ch.android.lookforkotlinv2.fragment

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import com.ch.android.lookforkotlinv2.R
import com.ch.android.lookforkotlinv2.databinding.FragmentHomeBlankBinding

/**
 * A simple [Fragment] subclass.
 * Use the [HomeBlankFragment.newInstance] factory method to
 * create an instance of this fragment.
 */
class HomeBlankFragment : Fragment() {
    // TODO: Rename and change types of parameters
    private var param1: String? = null
    private var param2: String? = null
    private var mBinding: FragmentHomeBlankBinding? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            param1 = it.getString(ARG_PARAM1)
            param2 = it.getString(ARG_PARAM2)
        }
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        if (mBinding == null) {
            mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_home_blank, container, false)
            mBinding?.lifecycleOwner = this // 这里的 this 指的是 Fragment
            mBinding!!.param1.text = param1
            mBinding?.param2?.text = param2
        }
        return mBinding?.root
    }

    companion object {
        private const val ARG_PARAM1 = "param1"
        private const val ARG_PARAM2 = "param2"
        @JvmStatic
        fun newInstance(param1: String, param2: String) =
            HomeBlankFragment().apply {
                arguments = Bundle().apply {
                    putString(ARG_PARAM1, param1)
                    putString(ARG_PARAM2, param2)
                }
            }
    }
}